package com.dmai.aiet.epc.archive.controller;

import com.dmai.aiet.epc.archive.base.Result;
import com.dmai.aiet.epc.archive.pojo.vo.LearningAggregateVo;
import com.dmai.aiet.epc.archive.pojo.vo.LearningCertificateVo;
import com.dmai.aiet.epc.archive.pojo.vo.LearningStatVo;
import com.dmai.aiet.epc.archive.service.StudyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * 我的档案
 */
@Slf4j
@RestController
public class MyArchiveController {

    @Autowired
    private StudyService studyService;

    /**
     * 我的学习统计
     */
    @GetMapping("/archives/v1/aggregate")
    public Result<LearningAggregateVo> getAggregate(String userid) {
        LearningAggregateVo result = studyService.getAggregate(userid);
        return Result.success(result);
    }

    /**
     * 学习趋势图
     *
     * @param userid     用户id
     * @param axle       x轴颗粒度  1：天，2：月
     * @param startStamp
     * @param endStamp
     * @return
     */
    @GetMapping("/archives/v1/stat")
    public Result<LearningStatVo> getStatistics(@RequestParam(value = "userid") String userid,
                                                @RequestParam(value = "axle", defaultValue = "1") Integer axle, Long startStamp, Long endStamp) {
        LearningStatVo result = studyService.getStat(userid, axle, startStamp, endStamp);
        return Result.success(result);
    }


    /**
     * 我的证书
     *
     * @param userid
     * @param category 类型：空表示全部
     * @param limit    限制条数：空表示全部
     * @return
     */
    @GetMapping("/archives/v1/certificate")
    public Result<LearningCertificateVo> getCertificate(@RequestParam(value = "userid") String userid,
                                                        @RequestParam(value = "category", defaultValue = "") String category,
                                                        @RequestParam(value = "limit", defaultValue = "") Integer limit) {
        LearningCertificateVo result = studyService.getCertificate(userid, category, limit);
        return Result.success(result);
    }
}
